package com.java.comprehensive.arithmetic.coding_interview;

import java.util.ArrayList;

import util.ListNode;

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Kth_Node_From_End_of_List_LCCI {
	public int kthToLast(ListNode head, int k) {
		ArrayList<Integer> list = new ArrayList<>();

		while (head != null) {
			list.add(head.val);
			head = head.next;
		}

		return list.get(list.size() - k);
	}
}